//--------------------------------------------------------------------------------------------------------------
// <copyright file="CSPMyProperty.cs" company="Microsoft Corporation" author="David Martos" date="01/02/2008">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
//--------------------------------------------------------------------------------------------------------------
using System;
using System.Data;
using System.Runtime.InteropServices;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;
using System.ComponentModel;

using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;

using CSP.LoggingEngine;

namespace CSP.WebParts
{
    /// <summary>
    /// This webpart gets the list of membership requests
    /// </summary>
    [Guid("A8867326-80E6-4de7-8617-6A099E43DD20")]
    public class CSPMembershipRequestList : BaseWebPart, INamingContainer
    {

        #region members
        protected Label errorLabel;
        protected int pageSize;
        private const int PageSizeDefault = 10;
        #endregion

        #region properties
        [Personalizable(PersonalizationScope.Shared)]
        [WebBrowsable(true)]
        [ResourcesAttribute("DefaultPageSize", "CSPWebPartParameterCategory", "DefaultPageSizeDescription")]
        [DefaultValue(PageSizeDefault)]
        public int PageSize
        {
            get { return this.pageSize; }
            set { this.pageSize = value; }
        }
        #endregion


        #region methods
        /// <summary>
        /// Constructor
        /// </summary>
        public CSPMembershipRequestList()
        {
            this.ExportMode = WebPartExportMode.All;
        }



        /// <summary>
        /// Fired on page create child control, loads the ASCX file
        /// </summary>
        protected override void CreateChildControls()
        {

            base.CreateChildControls();

            try
            {
                if (CSP.Core.MembershipHelper.IsCurrentUserCivilServant())
                {
                    this.Hidden = false;

                    UserControls.CSPMembershipRequestListWUC control = (UserControls.CSPMembershipRequestListWUC)Page.LoadControl(WebPartConstants.CSPMembershipRequestListWUC);
                    control.WrapperWebPart = this;
                    control.PageSize = this.pageSize;                   
                    this.Controls.Add(control);
                }
                else
                {
                    this.Hidden = true;
                }

            }
            catch (CSP.Core.CSPException cspex)
            {
                errors.Add(this.LoadResource(WebPartConstants.CSPGenericErrorMessage));
            }
            catch (Exception ex)
            {
                this.LogMessage(this.LoadResource(WebPartConstants.CSPLoadControlErrorMessage), this.GetType().Name, ex);
                errors.Add(this.LoadResource(WebPartConstants.CSPGenericErrorMessage));
            }
        }
        #endregion
    }
}
